package net.sareweb.acab.session;

import net.sareweb.acab.entity.*;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("commentHome")
public class CommentHome extends EntityHome<Comment> {

	@In(create = true)
	DialogHome dialogHome;
	@In(create = true)
	UserHome userHome;

	public void setCommentIdComment(Integer id) {
		setId(id);
	}

	public Integer getCommentIdComment() {
		return (Integer) getId();
	}

	@Override
	protected Comment createInstance() {
		Comment comment = new Comment();
		return comment;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		Dialog dialog = dialogHome.getDefinedInstance();
		if (dialog != null) {
			getInstance().setDialog(dialog);
		}
		User user = userHome.getDefinedInstance();
		if (user != null) {
			getInstance().setUser(user);
		}
	}

	public boolean isWired() {
		if (getInstance().getDialog() == null)
			return false;
		if (getInstance().getUser() == null)
			return false;
		return true;
	}

	public Comment getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

}
